<?php
/**
 * Created by PhpStorm.
 * User: a4041
 * Date: 2018/6/13
 * Time: 13:46
 */

namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class News extends Model
{
    protected $table = 'news';

        protected $appends = ['catname'];       // 表里没有的字段


    // 处理订单未处理金额
    public function getCatnameAttribute()
    {
        $catid = $this->attributes['catid'];  // $this->attributes表的字段属性
        try{
            $res = NewsType::find($catid);
            if(!$res){
                $catname = '';
            }
            $catname = $res->name;
        }catch (\Exception $e){
            $catname = '';
        }


        return $catname;
    }
}